package com.sq.universe.base.utils;

import com.sq.universe.log.feign.LogFeign;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;


@Component
public class ApplicationContextUtils<T> implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Autowired
    private LogFeign logFeign;

    public static LogFeign logFeignStatic;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationContextUtils.applicationContext = applicationContext;
    }

    public static <T> T  getBean(Class<T> clazz) {
        return applicationContext != null?applicationContext.getBean(clazz):null;
    }




    @PostConstruct
    public void init() {
        logFeignStatic = logFeign;
    }
}
